#include "GRange.h"
#include "GError.h"

namespace GEngine
{
	// Description: Constructor
	// Return:
	// Notes: MinCount is one, so task can be divided untill there is one item!
	// ----------------------------------------------------
	GTaskRange::GTaskRange(GSize IndexFirst, GSize IndexLast)
	{
		this->IndexFirst = IndexFirst;
		this->IndexLast = IndexLast;
		this->Granularity = 1;
	}

	// Description: Constructor
	// Return:
	// Notes:
	// ----------------------------------------------------
	GTaskRange::GTaskRange(GSize IndexFirst, GSize IndexLast, GSize Granularity)
	{
		this->IndexFirst = IndexFirst;
		this->IndexLast = IndexLast;
		this->Granularity = Granularity;
	}

	// Description: Destructor
	// Return:
	// Notes:
	// ----------------------------------------------------
	GTaskRange::~GTaskRange()
	{
	}

	void GTaskRange::TrimBack(GSize NewLastIndex)
	{
		GUtil::GError::DebugCheck(NewLastIndex > IndexLast, "New index bigger than last");
		GUtil::GError::DebugCheck(NewLastIndex < IndexFirst, "New index lower than first");

		IndexLast = NewLastIndex;
	}

	void GTaskRange::TrimFront(GSize NewFirstIndex)
	{
		GUtil::GError::DebugCheck(NewFirstIndex > IndexLast, "New index bigger than last");
		GUtil::GError::DebugCheck(NewFirstIndex < IndexFirst, "New index lower than first");

		IndexFirst = NewFirstIndex;
	}

	// Description: Accessor method
	// Return: Returns first task index of the range
	// Notes:
	// ----------------------------------------------------
	GSize GTaskRange::GetIndexFirst() const
	{
		return IndexFirst;
	}

	// Description:  Accessor method
	// Return: Returns last task index of the range
	// Notes:
	// ----------------------------------------------------
	GSize GTaskRange::GetIndexLast() const
	{
		return IndexLast;
	}

	// Description: Accessor method
	// Return: Returns minimum allowed task count of the range
	// Notes:
	// ----------------------------------------------------
	GSize GTaskRange::GetGranularity() const
	{
		return Granularity;
	}

}